package com.hhxy.consumer;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Date;


/**
 * @author ghp
 * @date 2023/2/25
 * @title
 * @description 消费来自死信队列中的延迟消息（基于死信队列实现延迟队列）
 */
@Slf4j
@Component
public class DeadLetterQueueConsumer {

    /**
     * 监听死信队列中的消息
     */
    @RabbitListener(queues = "C")
    public void receiveC(Message message){
        String msg = new String(message.getBody());
        String expiration = message.getMessageProperties().getExpiration();
        log.info("当前时间:{}, 收到死信队列的消息:{}, 该消息的有效期为: {}", new Date(), msg, expiration);
    }
}
